﻿<TabItem x:Class="VkClientIM.UI.ConversationPresenter"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:UI="clr-namespace:VkClientIM.UI" mc:Ignorable="d" 
             d:DesignHeight="301" d:DesignWidth="438">
	<TabItem.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="..\Resources\ListView.xaml"/>
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</TabItem.Resources>
	<TabItem.Header>
		<StackPanel Orientation="Horizontal">
			<Image Name="buddyImage" Source="{Binding Path=Buddy.Photo, Converter={StaticResource imageConverter}}" MaxHeight="50" MaxWidth="50"/>
			<StackPanel>
				<TextBlock Text="{Binding Path=Buddy.FirstName}"/>
				<TextBlock Text="{Binding Path=Buddy.NickName}"/>
				<TextBlock Text="{Binding Path=Buddy.LastName}"/>
			</StackPanel>
		</StackPanel>
	</TabItem.Header>
	<TabItem.Content>
		<Grid>
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="*"/>
				<RowDefinition Height="3"/>
				<RowDefinition Height="30"/>
			</Grid.RowDefinitions>
			<Image Name="myImage" Visibility="Collapsed" Source="{Binding Path=MyProfile.Photo, Converter={StaticResource imageConverter}}"/>
			<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Grid.Row="0">
				<TextBlock Text="{Binding Path=Buddy.FirstName}" FontSize="20" Foreground="DarkBlue"/>
				<TextBlock Text=" " FontSize="20"/>
				<TextBlock Text="{Binding Path=Buddy.NickName}" FontSize="20" Foreground="DarkBlue"/>
				<TextBlock Text=" " FontSize="20"/>
				<TextBlock Text="{Binding Path=Buddy.LastName}" FontSize="20" Foreground="DarkBlue"/>
			</StackPanel>
			<ListView Grid.Row="1" Name="messagesPresenter" ItemsSource="{Binding Path=Messages}" ScrollViewer.ScrollChanged="messagesPresenter_ScrollChanged">
				<ListView.ItemTemplate>
					<DataTemplate>
						<Border Name="border" CornerRadius="5" BorderBrush="Black" BorderThickness="1">
							<DockPanel Margin="5,5,5,5">
								<Image Name="image" Height="50" Width="50" DockPanel.Dock="Left"/>
								<StackPanel>
									<TextBlock Text="{Binding Path=WindowsTime}" FontWeight="Bold"/>
									<TextBlock TextWrapping="Wrap" Text="{Binding Path=MessageBody}"/>
								</StackPanel>
							</DockPanel>
						</Border>
						<DataTemplate.Triggers>
							<DataTrigger Binding="{Binding Path=Out}" Value="True">
								<Setter TargetName="image" Property="Source" Value="{Binding ElementName=myImage, Path=Source}"/>
								<Setter TargetName="border" Property="Background">
									<Setter.Value>
										<LinearGradientBrush StartPoint="1,0">
											<GradientStop Color="White" Offset="0"/>
											<GradientStop Color="LightBlue" Offset="0.5"/>
											<GradientStop Color="White" Offset="1"/>
										</LinearGradientBrush>
									</Setter.Value>
								</Setter>
							</DataTrigger>
							<DataTrigger Binding="{Binding Path=Out}" Value="False">
								<Setter TargetName="image" Property="Source" Value="{Binding ElementName=buddyImage, Path=Source}"/>
								<Setter TargetName="border" Property="Background">
									<Setter.Value>
										<LinearGradientBrush StartPoint="1,0">
											<GradientStop Color="White" Offset="0"/>
											<GradientStop Color="LightGreen" Offset="0.5"/>
											<GradientStop Color="White" Offset="1"/>
										</LinearGradientBrush>
									</Setter.Value>
								</Setter>
							</DataTrigger>
						</DataTemplate.Triggers>
					</DataTemplate>
				</ListView.ItemTemplate>
				<ListView.ItemContainerStyle>
					<Style BasedOn="{StaticResource MyListViewItem}" TargetType="{x:Type ListViewItem}">
					</Style>
				</ListView.ItemContainerStyle>
			</ListView>
			<GridSplitter Background="Red" Grid.Row="2" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

			<DockPanel Grid.Row="3" >
				<Button DockPanel.Dock="Right" Width="100" Content="Отправить" Click="SendClick"/>
				<TextBox Name="messageTextBox" AcceptsReturn="true" KeyDown="messageTextBox_KeyDown"/>
			</DockPanel>
		</Grid>
	</TabItem.Content>
</TabItem>
